//
//  InfoManager.m
//  mendianjieke
//
//  Created by 响当当 on 8/5/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "InfoManager.h"

@implementation InfoManager
/**
 *   初始化
 */
+ (InfoManager *_Nonnull)manager
{
    static InfoManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!manager) {
            manager = [[InfoManager alloc]init];
        }
    });
    return manager;
}

/**
 *   获取验证码
 */
- (void)getCodeWithPhone:(NSString *_Nonnull)phoneStr Sucess:(void(^_Nonnull)(id _Nonnull acceptData))sucess fail:(nonnull void(^ )( NSError * _Nullable error))fail
{
    
    NSDictionary *prarmers = @{
                               @"phoneNum" : phoneStr
                               };
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(kAPI_GETCODE) withPramater:prarmers sucess:^(id responseObject) {
        sucess(responseObject);
    } failure:^(NSError *error) {
        fail(error);
    }];
}


- (void)getLoginRequestWithParamers:(NSDictionary *)paramers sucess:(void (^)(void))sucess fail:(void (^)(NSError *error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_LOGIN) withPramater:paramers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        
        NSString *token = dic[@"access_token"];
        NSString *refreshToken = dic[@"refresh_token"];
        current_User.token = token;
        current_User.refrehToken = refreshToken;
        current_User.username = @"15950167365";
//        current_User.userID = dic[@"userId"];
//        current_User.nickName = dic[@"nickName"];
//        current_User.isHideinfo = dic[@"isAppInfo"];
        current_User.hasLogin = @"1";
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            [current_User savaSessionSucess:^{
                if (sucess) {
                    sucess();
                }
            } fail:^(NSError *error) {
                
            }];
        }];
        
        
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"登录失败，请重试"];
        DISMISS_SVP(1.0f);
        fail(error);
    }];
}

/**
 *  验证token
 */
- (void)checkTokenParamers:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_CHECKTOKEN) withPramater:prarmers sucess:^(id responseObject) {
        
        sucess(responseObject);

    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  实时获取接客信息
 */
- (void)getTimeInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager getRequestUrl:FULL_WEB_URL(KAPI_FETCUSTOMERINFO) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  取消接客
 */
- (void)cancelCustomer:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_CANCELSERVERCUSTOMER) withPramater:prarmers sucess:^(id responseObject) {
        
        sucess(responseObject);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  获取顾客信息
 */
- (void)getCustomerInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_CUSTOMERINFO) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  获取顾客攻略信息
 */
- (void)getCustomerAttackInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_CUSTOMERATTACKINFO) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  获取用户信息
 */
- (void)getUserInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_USERINFO) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  获取活动信息
 */
- (void)getActivityInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager getRequestUrl:FULL_WEB_URL(KAPI_ACTIVITY) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  开启设备或关闭设备
 */
- (void)getSwitchOnInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_SWITCHON) withPramater:prarmers sucess:^(id responseObject) {
        
        sucess(responseObject);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  人脸认证
 */
- (void)postFaceInfo:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_FACE) withPramater:prarmers sucess:^(id responseObject) {
        
        sucess(responseObject);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  退出登录
 */
- (void)logOut:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_LOGOUT) withPramater:prarmers sucess:^(id responseObject) {
        
        sucess(responseObject);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  获取折线图
 */
- (void)recordLineChart:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager getRequestUrl:FULL_WEB_URL(KAPI_RECORDLINECHART) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  顾客记录表
 */
- (void)recordList:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_RECORDLIST) withPramater:prarmers sucess:^(id responseObject) {
        
        sucess(responseObject);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}

/**
 *  店内统计
 */
- (void)recordStatistics:(NSDictionary *_Nonnull)prarmers sucess:(void(^_Nullable)(id _Nonnull acceptData))sucess fail:(nonnull void(^)( NSError * _Nullable error))fail
{
    [NetWorkingManager postRequestUrl:FULL_WEB_URL(KAPI_STATISTICS) withPramater:prarmers sucess:^(id responseObject) {
        
        NSDictionary *dic = responseObject[@"data"];
        sucess(dic);
        
    } failure:^(NSError *error) {
        fail(error);
    }];
}
@end
